<%@ taglib prefix="wctags" tagdir="/WEB-INF/tags"%>
<%response.setContentType("text/html; charset=UTF-8");%><%@ taglib
	uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><%@taglib
	uri="http://www.ptc.com/windchill/taglib/fmt" prefix="fmt"%>
<%@ include file="/netmarkets/jsp/components/beginWizard.jspf"%>

<%@ page
	import="wt.util.InstalledProperties,
		wt.inf.container.WTContainerRef,
		com.ptc.netmarkets.util.beans.NmCommandBean,
		wt.fc.ReferenceFactory,
		com.ptc.windchill.enterprise.util.PartManagementHelper"%>
<%@page import="ext.acae2.baseline.resource.BaselineActionResource"%>
<%
    WTContainerRef containerRef = commandBean.getContainerRef();
    boolean isProjectLink = ((containerRef != null) && (PartManagementHelper.isProjectLink(containerRef)));
        
    if (isProjectLink) {
        request.setAttribute("baselineComponentId", "ProjectLink.BaselineAddItems");
        
        ReferenceFactory rf = new ReferenceFactory();
        request.setAttribute("containerRef", rf.getReferenceString(containerRef));
        
        if(InstalledProperties.isInstalled(InstalledProperties.ARBORTEXT_CM)){
	   request.setAttribute("baselineComponentId", "ArbortextWithProjectLink.BaselineAddItems");
	}
        
    } else {	    
	    request.setAttribute("baselineComponentId", "PDMLink.BaselineAddItems");	    	    	
	    request.setAttribute("containerRef", "");
	    
	    if(InstalledProperties.isInstalled(InstalledProperties.ARBORTEXT_CM)){
	    	request.setAttribute("baselineComponentId", "ArbortextContentManager.BaselineAddItems");
	    }
    }

%>

<fmt:setBundle
	basename="com.ptc.windchill.enterprise.baseline.baselineResource" />
<fmt:message var="addToBaselinePickerTitle"
	key="BASELINE_ADD_PICKER_TITLE" />

<c:if
	test="<%=InstalledProperties.isInstalled(InstalledProperties.PRO_I)%>">
	<c:set var="baselineComponentId" value="ProI.BaselineAddItems" />
</c:if>

<wctags:itemPicker id="baselineMemberItemPicker" multiSelect="true"
	inline="true" typeComponentId="${baselineComponentId}"
	pickerTitle="${addToBaselinePickerTitle}" pickerCallback="doNothing"
	containerRef="${containerRef}" />
<input value="addMembers" name="addToBaseline_flag" type="hidden" />
<script Language="JavaScript">

  function user_validate(){
  
	 var leftPaneOccupants = /doc\.WTDocument|epm\.EPMDocument|part\.WTPart/;
     var searchObjects = document.getElementsByName("pjl_selPJLsa1__1");
	 for(var i=0;i<searchObjects.length;i++){
	    var searchObject = searchObjects[i];
		var searchObjValue = searchObject.value;
		var objOid = searchObjValue.substring(searchObjValue.lastIndexOf("$")+1,searchObjValue.indexOf("!"));
		if(!objOid.match(leftPaneOccupants)){
			JCAAlert("ext.acae2.baseline.resource.BaselineActionResource.BASELINEABLE_TYPE_ERROR");
			return false;
		}
	 }
	 var flag = PTC.validation.callAJAXValidation('BaselineableStateValidator');
	 return flag;
  }
  
  setUserSubmitFunction(user_validate);
  
</script>

<%@ include file="/netmarkets/jsp/util/end.jspf"%>
